//
// Created by Semir on 2020/6/5.
//

#include <iostream>
#include "../Util/Tree.h"

using namespace std;

bool isBalance;

int TreeDepth(TreeNode* pRoot) {
    if (pRoot == nullptr || !isBalance) {
        return 0;
    }
    int leftDepth = TreeDepth(pRoot->left);
    int rightDepth = TreeDepth(pRoot->right);
    if (abs(leftDepth - rightDepth) > 1) {
        isBalance = false;
    }
    int depth = max(leftDepth, rightDepth) + 1;
    return depth;
}

bool IsBalanced_Solution(TreeNode* pRoot) {
    isBalance = true;
    TreeDepth(pRoot);
    return isBalance;
}

int main() {
    TreeNode* root = TestTree5();
    bool res = IsBalanced_Solution(root);
    cout << res << endl;
    return 0;
}